package com.cityu.bac.rfidDriver;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import android.bluetooth.BluetoothDevice;
import android.util.Log;

class BluetoothUtils {


	    static public boolean createBond(BluetoothDevice btDevice) throws Exception {  
	        Method createBondMethod = btDevice.getClass().getMethod("createBond");  
	        Boolean returnValue = (Boolean) createBondMethod.invoke(btDevice);  
	        Log.e("createBond returnValue", "" + returnValue);  
	        return returnValue.booleanValue();  
	    }  

	    static public boolean removeBond(Class btClass,BluetoothDevice btDevice) throws Exception {  
	        Method removeBondMethod = btClass.getMethod("removeBond");  
	        Boolean returnValue = (Boolean) removeBondMethod.invoke(btDevice);  
	        return returnValue.booleanValue();  
	    }  

	    static public boolean setPin(BluetoothDevice btDevice,  
	            String str) throws Exception {  
	        try {             
	            Method removeBondMethod = btDevice.getClass().getDeclaredMethod("setPin",  
	                    new Class[] { byte[].class });  
	            Boolean returnValue = (Boolean) removeBondMethod.invoke(btDevice,  
	            new Object[] { str.getBytes() });  
	            Log.e("setPin returnValue", "" + returnValue);  
	        } catch (SecurityException e) {  
	            // throw new RuntimeException(e.getMessage());  
	            e.printStackTrace();  
	        } catch (IllegalArgumentException e) {  
	            // throw new RuntimeException(e.getMessage());  
	            e.printStackTrace();  
	        } catch (Exception e) {  
	            // TODO Auto-generated catch block  
	            e.printStackTrace();  
	        }  
	        return true;  

	    }  

	    static public void printAllInform(Class clsShow) {  
	        try {  
	            // 取得所有方法  
	            Method[] hideMethod = clsShow.getMethods();  
	            int i = 0;  
	            for (; i < hideMethod.length; i++) {  
	                Log.e("method name", hideMethod[i].getName());  
	            }  
	            // 取得所有常量  
	            Field[] allFields = clsShow.getFields();  
	            for (i = 0; i < allFields.length; i++) {  
	                Log.e("Field name", allFields[i].getName());  
	            }  
	        } catch (SecurityException e) {  
	            // throw new RuntimeException(e.getMessage());  
	            e.printStackTrace();  
	        } catch (IllegalArgumentException e) {  
	            // throw new RuntimeException(e.getMessage());  
	            e.printStackTrace();  
	        } catch (Exception e) {  
	            // TODO Auto-generated catch block  
	            e.printStackTrace();  
	        }  
	    }  
	} 